package com.kk.nb_order.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;


/**
 * @Author: K
 * @Date: 2024/11/11
 */
@Configuration
public class RabbitMQConfig {

    @Bean
    public Queue orderQueue() {
        Map<String,Object> map = new HashMap<>();
        //设置ttl时间，即Time To Live 存活时间
        map.put("x-message-ttl", 1000*60);//1分钟
        //配置消息存活时间结束后的处理方式
        map.put("x-dead-letter-exchange", "deadExchange");
        map.put("x-dead-letter-routing-key", "dead");
        return new Queue("orderQueue",true,false,false,map);
    }
    @Bean
    public DirectExchange orderExchange() {

        return new DirectExchange("orderExchange");
    }
    @Bean
    public Binding orderBinding() {
        return BindingBuilder.bind(orderQueue()).to(orderExchange()).with("order");
    }


    @Bean
    public Queue deadQueue() {
        return new Queue("deadQueue");
    }
    @Bean
    public DirectExchange deadExchange() {
        return new DirectExchange("deadExchange");
    }
    @Bean
    public Binding deadBinding() {
        return BindingBuilder.bind(deadQueue()).to(deadExchange()).with("dead");
    }
}

